<?php

	require_once 'datePicker.php';
	
	function createUser() {
	require_once 'db-connection.php';
		if(isset($_POST['submit'])) {
			$birthdate = manageDate('birth_date');
			$username = $_POST['username'];
			$password = sha1($_POST['password']);
			$email = $_POST['email'];
			$checkUserName = mysql_query("select * from users where username = '$username'");
			$checkEmail = mysql_query("select * from users where e_mail = '$email'");
			if(mysql_fetch_array($checkUserName)) {
				echo "<p><h1>The chosen username already exists!</h1></p>";
				exit;
			}
			elseif (mysql_fetch_array($checkEmail)) {
				echo "<p><h1>The chosen email address already exists!</h1></p>";
				exit;
			}
			else {
				$createUser = mysql_query("insert into users(username, password, birthDate, e_mail)
						values('$username', '$password', '$birthdate', '$email');");
				echo "<p>User Created Successfully!!</p><br />";
				echo "<a href='root-user-admin.php' style='background-color:lightblue; font-size:2em; text-decoration:none'>Go Back</a>";
			}
		}
	}
	
	
	createUser();
	
?>	